﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using L = Science.Mathematics.LinearAlgebra;

namespace Strang3Ed.Chapter02.Section2
{
    public class Example03
    {
        public Example03()
        {
        }
        private string result;
        public string Result
        {
            get { return result; }
        }
        public void Compute()
        {
            double[,] x = {{0.0,2.0},
                           {3.0,-2.0}};

            L.Matrix A = new L.Matrix(x);
            L.FactorizationPAeqLU obj = new L.FactorizationPAeqLU(A);
            obj.Compute();
            L.Matrix LU = obj.LowerTriangular * obj.UpperTriangular;

            L.Matrix PA = obj.RowPermutation * A;

            result += PA[0, 0].ToString() + "    ";
            result += PA[0, 1].ToString() + "\r\n";

            result += PA[1, 0].ToString() + "    ";
            result += PA[1, 1].ToString() + "\r\n" + "\r\n";

            result += LU[0, 0].ToString() + "    ";
            result += LU[0, 1].ToString() + "\r\n";

            result += LU[1, 0].ToString() + "    ";
            result += LU[1, 1].ToString() + "\r\n" + "\r\n";

            result += obj.LowerTriangular[0, 0].ToString() + "    ";
            result += obj.LowerTriangular[0, 1].ToString() + "\r\n";

            result += obj.LowerTriangular[1, 0].ToString() + "    ";
            result += obj.LowerTriangular[1, 1].ToString() + "\r\n" + "\r\n";

            result += obj.UpperTriangular[0, 0].ToString() + "    ";
            result += obj.UpperTriangular[0, 1].ToString() + "\r\n";

            result += obj.UpperTriangular[1, 0].ToString() + "    ";
            result += obj.UpperTriangular[1, 1].ToString() + "\r\n" + "\r\n";

            result += A.Determinant.ToString();

        }
    }
}
/*
3    -2
0    2

3    -2
0    2

1    0
0    1

3    -2
0    2

-6
*/

